# Contributor: Fernando Casas Schossow <casasfernando@outlook.com>
# Maintainer: Fernando Casas Schossow <casasfernando@outlook.com>
pkgname=ocaml-gettext
pkgver=0.3.7
pkgrel=0
pkgdesc="OCaml library for i18n"
url="https://github.com/gildor478/ocaml-gettext"
arch="aarch64 ppc64le x86_64" # restricted by ocaml
license="LGPL-2.1-or-later-WITH-linking-exception"
makedepends="ocaml ocaml-ocamldoc ocaml-camlp4-dev ocaml-fileutils ocaml-fileutils-dev ocaml-findlib-dev chrpath autoconf automake libxml2 libxslt docbook-xsl gettext-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="${pkgname}-${pkgver}.tar.gz::https://github.com/gildor478/$pkgname/archive/$pkgver.tar.gz
	0001-pr_gettext-stop-tracking-and-printing-untranslated-s.patch
	0002-pr_gettext-stop-printing-extracted-strings.patch
	0003-add-more-generated-files-to-.gitignore.patch
	ocaml-gettext-0.3.4-use-ocamlopt-g.patch"
builddir="$srcdir/$pkgname-$pkgver"
options="!check" # there is no test suite/unit tests since tests requires camomile

prepare() {
	default_prepare
	autoreconf -i
}

build() {
	cd "$builddir"
	unset MAKEFLAGS
	export OCAMLPARAM="safe-string=0,_"
	sed -i 's/@OCAMLDOC@/@OCAMLDOC@ -unsafe-string/g' ConfMakefile.in
	./configure --prefix=/usr --disable-camomile --with-docbook-stylesheet=/usr/share/xml/docbook/xsl-stylesheets-1.79.1 --with-stub-ldflags=-lintl
	make all
}

package() {
	cd "$builddir"
	export DESTDIR="$pkgdir"
	export OCAMLFIND_DESTDIR="$DESTDIR/usr/lib/ocaml"
	mkdir -p "$OCAMLFIND_DESTDIR" "$OCAMLFIND_DESTDIR/stublibs"
	find _build -name '*.o' -exec rm {} \;
	ocamlfind install gettext _build/lib/gettext/*
	ocamlfind install gettext-stub _build/lib/gettext-stub/*
	install -D -m644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
	install -D -m 0755 _build/bin/ocaml-gettext "$pkgdir/usr/bin/ocaml-gettext"
	install -D -m 0755 _build/bin/ocaml-xgettext "$pkgdir/usr/bin/ocaml-xgettext"
	chrpath --delete $OCAMLFIND_DESTDIR/stublibs/dll*.so
}

sha512sums="1358320359b9d2f3fd97a47d69b2a619942a65605c1e5cbf25e33ef42a10273167b526bca15e6c9523b87d8ea9dfd3215334050ad8eb84a8c41d4feef880a27a  ocaml-gettext-0.3.7.tar.gz
430e67b9e228d36eae6d1a1378c40d3203799d04c05962d25be4703483418400d71c392c2d84baa434f5e7aab19e7925e08971392b969ff472e3baf81546ca6d  0001-pr_gettext-stop-tracking-and-printing-untranslated-s.patch
69f9e5a000cd29b5f6e7ee1b3ce0691ba4a7fdff456c76ce271daa76a74cf422aa8769f94cac46dbceb92dcdcdaecfbc65e255f61748bd52e7ccf7e88cc04bac  0002-pr_gettext-stop-printing-extracted-strings.patch
6cab63660875ec9f6314631ae0730870b714b5a1bc456d97a04c928f287feb82aae623b8361b6b56075901f2d9cd5716e27305cda4334ac0e61a40ce02bab599  0003-add-more-generated-files-to-.gitignore.patch
b169f864194459db388ee8aa9db4cf97441419cb6b93c1b72854cca3fbbdcab8745a802326f967b8786853ec136aca41847799100216d6f9272e6a56dc80d169  ocaml-gettext-0.3.4-use-ocamlopt-g.patch"
